#Posts                       : 3000000
#Open Posts                  : 2942293
#Off Topic Posts             : 14605
#Not Constructive Posts      : 13607
#Not a Real Question Posts   : 24617
#Too Localized Posts         : 4878

totalPosts = float(3370528)
openPosts = float(3300392)
offTopicPosts = float(17530)
notConstructivePosts = float(15659)
notARealQuestionPosts = float(30789)
tooLocalizedPosts = float(6158)

#Setting these manually for private leaderboard testing
openRate = float(0.926642216133641)
offTopicRate = float(0.018430671606251586)
notConstructiveRate = float(0.01173872976800856)
notARealQuestionRate = float(0.03410911204982466)
tooLocalizedRate = float(0.009079270442274271)

#openRate = openPosts/totalPosts
#offTopicRate = offTopicPosts/totalPosts
#notConstructiveRate = notConstructivePosts/totalPosts
#notARealQuestionRate = notARealQuestionPosts/totalPosts
#tooLocalizedRate = tooLocalizedPosts/totalPosts

oldOpenRate = float(.2)
oldOffTopicRate = float(.2)
oldNotConstructiveRate = float(.2)
oldNotARealQuestionRate = float(.2)
oldTooLocalizedRate = float(.2)

def setToUniformBenchmark(probabilities):
	for probability in probabilities:
		probability.open = float(.2)
		probability.offTopic = float(.2)
		probability.notConstructive = float(.2)
		probability.notARealQuestion = float(.2)
		probability.tooLocalized = float(.2)

def setToPriorBenchmark(probabilities):
	for probability in probabilities:
		probability.open = openRate
		probability.offTopic = offTopicRate
		probability.notConstructive = notConstructiveRate
		probability.notARealQuestion = notARealQuestionRate
		probability.tooLocalized = tooLocalizedRate
		
def setToMyBenchmark(probabilities):
	for probability in probabilities:
		probability.open = .996
		probability.offTopic = .001
		probability.notConstructive = .001
		probability.notARealQuestion = .001
		probability.tooLocalized = .001
		
def adjustForPriors(probabilities):
	for probability in probabilities:
		probability.open = probability.open * (openRate/oldOpenRate)
		probability.offTopic = probability.offTopic * (offTopicRate/oldOffTopicRate)
		probability.notConstructive = probability.notConstructive * (notConstructiveRate/oldNotConstructiveRate)
		probability.notARealQuestion = probability.notARealQuestion * (notARealQuestionRate/oldNotARealQuestionRate)
		probability.tooLocalized = probability.tooLocalized * (tooLocalizedRate/oldTooLocalizedRate)

def capProbabilities(probabilities,epsilon):
	for probability in probabilities:
		probability.cap(epsilon)

#def updateProbability(probability,epsilon):
#	probability.cap(epsilon)
#	probability.open = probability.open * (openRate/oldOpenRate)
#	probability.offTopic = probability.offTopic * (offTopicRate/oldOffTopicRate)
#	probability.notConstructive = probability.notConstructive * (notConstructiveRate/oldNotConstructiveRate)
#	probability.notARealQuestion = probability.notARealQuestion * (notARealQuestionRate/oldNotARealQuestionRate)
#	probability.tooLocalized = probability.tooLocalized * (tooLocalizedRate/oldTooLocalizedRate)
#	probability.cap(epsilon)
	
def updateProbabilities(probabilities,epsilon):
	capProbabilities(probabilities,epsilon)
	adjustForPriors(probabilities)
	capProbabilities(probabilities,epsilon)
